package com.zlzxm.zutil.ui.widget.recyclerviewutil;

import android.graphics.Rect;
import android.view.View;

import com.zlzxm.zutil.ui.viewhelp.ZViewHelp;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by zlz
 * on  2019/6/26
 */
public class NormalBottomRightSpace extends RecyclerView.ItemDecoration {

    private final int bottomSpace ;
    private final int rightSpace ;

    public NormalBottomRightSpace(int bottomSpace, int rightSpace) {

        this.bottomSpace = bottomSpace;
        this.rightSpace = rightSpace;

    }


    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);

        if(parent.getChildAdapterPosition(view)  >0)
            if(parent.getAdapter() != null) {

                outRect.bottom = ZViewHelp.dpTopx(parent.getContext(), bottomSpace);

                if (parent.getChildAdapterPosition(view) % 2 == 1) {

                    outRect.left = ZViewHelp.dpTopx(parent.getContext(), rightSpace);
                }
                outRect.right = ZViewHelp.dpTopx(parent.getContext(), rightSpace);
            }
    }


}
